import { v4 as uuid } from 'uuid'

class StdFigureAttr {
  constructor({ url, width, height }) {
    // 图片的链接
    this.url = url
    // 宽-单位像素
    this.width = width
    // 高-单位像素
    this.height = height
  }
}

export class StdInlineFigureData {
  constructor({ dataId, attributes }) {
    // 数据唯一标识
    this.dataId = dataId || uuid()
    // 基本属性
    this.attributes = attributes ? new StdFigureAttr(attributes) : null
  }
}

export class StdInlineFigure {
  constructor(node) {
    this.node = node
  }
  get data() {
    return this.parseFigure(this.node)
  }
  parseFigure(block) {
    const rootAttr = block.dataset || {}
    const figureData = {
      dataId: rootAttr.id,
      attributes: {
        url: rootAttr.url,
        width: rootAttr.width || 30,
        height: rootAttr.height || 30
      }
    }
    return figureData
  }
}

export class StdNakedFigure extends StdInlineFigure {}
export class StdNakedFigureData extends StdInlineFigureData {}
